Ext.define('PJ.view.unitregistrationmanagement.ViewSignupStatusListButton', {
    extend: 'AM.default.DefaultList',
	alias: 'widget.viewSignupStatusListButton',
	
    initComponent: function(){
    	var me = this;
    	if(me.clickSource==2){
        this.columns = [{
            header: '审核状态',
            dataIndex: 'c.auditing_State',
            width: 80,
            //sortable: false,
            renderer: function(v, meta, record){
            	meta.style="padding-bottom: 0px;padding-top: 0px;line-height: 19px;padding-left: 0px;";
                var text = "",tipText="";
                if (v == 3) {
                	tipText="报名待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">报名待审核</div>';
                }
                else if (v == 1) {
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过</div>';
                	tipText="报名通过";
                }else if (v == 2) {
                	tipText="点击查看驳回原因";
                	text= '<div style="border-left:5px solid red;height:19px;cursor: pointer;padding-left:2px;"><span style="cursor: pointer;color:blue;">报名未通过</span></div>';
                }else if(v == 4){
                	tipText="撤销待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">撤销待审核</div>';
                }else if(v == 5){
                	tipText="报名通过(撤销未通过)";
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过(<span style="cursor: pointer;color:blue;">撤销未通过</span>)</div>';
                }
                meta.tdAttr = 'data-qtip="' + tipText + '" auditStatus=' + record.get("c.auditing_State") + ' classUserId=' + record.get("classUserId") + ' userId=' + record.get("userId");
                return text;
            },
    		listeners: {
    			click: function(g, clm){
//    				var userId = clm.getAttribute("userId");
    				var auditStatus = clm.getAttribute("auditStatus");
    				var classUserId = clm.getAttribute("classUserId");
    				if(auditStatus == 5){
    					var win = Ext.create('PJ.view.registrationmanagement.CheckEdit', {
        					title: "查看驳回原因",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.findRejectReasonUrl,
        					params:{
        						classUserId: classUserId
        					},
        					success:function(f,action){
        					}
        				});
    				}else if(auditStatus == 2){
    					var win = Ext.create('PJ.view.trainingmanagement.CheckEdit', {
        					title: "查看驳回原因",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.findCommentUrl,
        					params:{
        						classUserId: classUserId
        					},
        					success:function(f,action){
        					}
        				});
    				}else{
    					return;
    				}
    			}
    		}
        },{
        	header: '学员帐号',
        	dataIndex: 'bu.login_id',
        	width: 75
        },{
        	header: '姓名',
        	dataIndex: 'bu.user_Name',
        	width: 75
        }, {
            header: '性别',
            dataIndex: 'bb.order_num',
            width: 45
        },{
            header: '出生年月',
            dataIndex: 'c.birthday',
            width: 70,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '民族',
            dataIndex: 'bt.order_num',
            width: 45,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            header: '手机号',
            dataIndex: 'c.mobile_Telephone',
            width: 100
        },/*{
            header: '单位',
            dataIndex: 'd.depname',
            width: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },*/{
            header: '职级',
            dataIndex: 'bbb.order_num',
            width: 135,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '单位及职务',
            dataIndex: 'c.duty_remark',
            flex: 1,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, /*{
            header: '联系电话',
            dataIndex: 't.mobileTelephone',
            width: 90,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },*/ {
            header: '备注',
            dataIndex: 'c.remark',
            flex:.5,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }]
        
    	} else{
        	this.columns = [{
                header: '审核状态',
                dataIndex: 'c.auditing_State',
                width: 80,
                //sortable: false,
                renderer: function(v, meta, record){
                	meta.style="padding-bottom: 0px;padding-top: 0px;line-height: 19px;padding-left: 0px;";
                    var text = "",tipText="";
                    if (v == 3) {
                    	tipText="报名待审核";
                    	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">报名待审核</div>';
                    }
                    else if (v == 1) {
                    	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过</div>';
                    	tipText="报名通过";
                    }else if (v == 2) {
                    	tipText="点击查看驳回原因";
                    	text= '<div style="border-left:5px solid red;height:19px;cursor: pointer;padding-left:2px;">报名未通过</div>';
                    }else if(v == 4){
                    	tipText="撤销待审核";
                    	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">撤销待审核</div>';
                    }else if(v == 5){
                    	tipText="报名通过(撤销未通过)";
                    	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过(<span style="cursor: pointer;color:blue;">撤销未通过</span>)</div>';
                    }
                    meta.tdAttr = 'data-qtip="' + tipText + '" auditStatus=' + record.get("c.auditing_State") + ' classUserId=' + record.get("classUserId") + ' userId=' + record.get("userId");
                    return text;
                },
               
        		listeners: {
        			click: function(g, clm){
        				var userId = clm.getAttribute("userId");
        				var auditStatus = clm.getAttribute("auditStatus");
        				var classUserId = clm.getAttribute("classUserId");
        				if(auditStatus == 5){
        					var win = Ext.create('PJ.view.registrationmanagement.CheckEdit', {
            					title: "查看驳回原因",
            					flag:4,
            					grid: me,
            					isDisable:false,
            					isReadOnly:true
            				}).show();
            				var actionName = "load";
            				if(gj_onlineLearning_constant.loadType == "jsonp"){
            					actionName = "loadJsonp";
            				}
            				win.down("form").getForm().doAction(actionName,{
            					url:me.store.findRejectReasonUrl,
            					params:{
            						userId: userId
            					},
            					success:function(f,action){
            					}
            				});
        				}else if(auditStatus == 2){
        					var win = Ext.create('PJ.view.trainingmanagement.CheckEdit', {
            					title: "查看驳回原因",
            					flag:4,
            					grid: me,
            					isDisable:false,
            					isReadOnly:true
            				}).show();
            				var actionName = "load";
            				if(gj_onlineLearning_constant.loadType == "jsonp"){
            					actionName = "loadJsonp";
            				}
            				win.down("form").getForm().doAction(actionName,{
            					url:me.store.findCommentUrl,
            					params:{
            						userId: userId
            					},
            					success:function(f,action){
            					}
            				});
        				}else{
        					return;
        				}
        			}
        		}
            },{
            	header: '学员帐号',
            	dataIndex: 'bu.login_id',
            	width: 75
            },{
            	header: '姓名',
            	dataIndex: 'bu.user_Name',
            	width: 75
            }, {
                header: '性别',
                dataIndex: 'bb.order_num',
                width: 45
            },{
                header: '出生年月',
                dataIndex: 'c.birthday',
                width: 70,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
                }
            }, {
                header: '民族',
                dataIndex: 'bt.order_num',
                width: 45,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
                }
            },{
                header: '手机号',
                dataIndex: 'c.mobile_Telephone',
                width: 100
            },
           {
                header: '单位',
                dataIndex: 'd.depname',
                width: 120,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
            }
            },{
                header: '职级',
                dataIndex: 'bbb.order_num',
                width: 135,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
                }
            }, {
                header: '单位及职务',
                dataIndex: 'c.duty_remark',
                flex: 1,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
                }
            }, /*{
                header: '联系电话',
                dataIndex: 't.mobileTelephone',
                width: 90,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
                }
            },*/ {
                header: '备注',
                dataIndex: 'c.remark',
                flex:.5,
                renderer: function(value, meta, record){
                    meta.tdAttr = 'data-qtip="' + value + '"';
                    return value;
                }
            }]
        };
        this.store = Ext.create('PJ.'+prototype+'.unitregistrationmanagement.ViewSignupStatusListButton', {
            isLoad: false
        });
        
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    //导出
    onExportClick: function(){
    	var me = this;
    	var store = me.getStore();
    	var params=store.proxy.extraParams;
    	var href=store.exportUrl + "?searchClassIds=" + me.up('window').classId;
    	for(var param in params){
    		if(params[param] === undefined){
    			href+="&"+param+"=";
    		}else{
    			if(param=="searchClassID"){
    				href+="&"+param+"="+params[param];
    			}else if(param=="clickSource"){
    				href+="&"+param+"="+params[param];
    			}
    		}
    	}
    	href = encodeURI(href);
    	var atag = Ext.get("exportResume");
    	atag.set({
    		"href": href
    	});
    	atag.dom.click();
    },
    //本班数量统计
    quotaOfPeople: function(){
    	var me = this;
        var quotaOfPeopleLabel = this.down("#signupQuotaOfPeople");
        var classNameStr = me.classType;
        var classId = me.up('window').classId;
        if (quotaOfPeopleLabel) {
            if(gj_onlineLearning_constant.loadType == "jsonp"){
            	var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
            		loadType: gj_onlineLearning_constant.loadType,
            		url: me.store.quotaOfPeopleUrl + '?searchClassId=' + classId
            	});
            	store1.load(function(rec, operation, success){
            		if(success){
            			var jsonData = operation.response.result;
            			quotaOfPeopleLabel.setText(
            					'本单位名额<span style="color:red">' + jsonData.asignCount +
            					'</span>人，已报<span style="color:red">' + jsonData.reportedNum +
            					'</span>人，剩余<span style="color:red">' + jsonData.surplusCount +
            					'</span>人。', false);
            		}
            	});
            }else if(gj_onlineLearning_constant.loadType == "ajax"){
            	Ext.Ajax.request({
            		url: me.store.quotaOfPeopleUrl + '?searchClassId=' + classId,
            		success: function(response){
            			var data = response.responseText;
            			var json = Ext.decode(data, true);
            			if (json.success) {
            				var jsonData = json.result;
            				quotaOfPeopleLabel.setText(
            						'本单位名额<span style="color:red">' + jsonData.asignCount +
                					'</span>人，已报<span style="color:red">' + jsonData.reportedNum +
                					'</span>人，剩余<span style="color:red">' + jsonData.surplusCount + 
                					'</span>人。', false);
            			}
            		}
            	});
            }
        }
    },
    listeners: {
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + 'Export').setDisabled(selected.length === 0);
    	},
    	viewready: function(){
    		if(this.clickSource==2){  
    		this.addDocked([{
                dock: 'top',
                xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: false,
                fieldDefaults: {
                    xtype: "textfield",
                    labelAlign: 'right',
                    labelWidth: 80
                },
                items: [{
                    fieldLabel: '学员帐号',
                    name: "searchLoginID",
                    emptyText: "请输入学员帐号",
        			columnWidth: .5,
                }, {
                    fieldLabel: "姓名",
                    name: "searchUserName",
                    emptyText: "请输入姓名",
        			columnWidth: .5,
                },/*{
                    fieldLabel: '单位',
                    name: "searchDepName",
                    emptyText: "请输入单位",
        			columnWidth: .4,
                },*//*,{
					xtype: "combo",
					fieldLabel: '审核状态',
					name: "auditingState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '审核通过'],[2,'未审核通过'],[3,'未审核']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}*/],
    			onResetClick: function(button){
    				
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
            				searchClassID: gridPanel.up('window').classId,
            				clickSource:this.up('window').clickSource,
            				auditingState: 1
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '导出',
                    iconCls: 'deriveIco',
                    itemId: this.oldId + "Export",
                    disabled: false,
                    scope: this,
                    handler: this.onExportClick
                }/*, "-", {
                    xtype: 'label',
                    itemId: 'signupQuotaOfPeople',
                    html: ''
                }*/]
            }]);
    		} else{
        		this.addDocked([{
                    dock: 'top',
                    xtype: "searchform",
        			columnCount: 2,
        			collapsedFieldSet: false,
                    fieldDefaults: {
                        xtype: "textfield",
                        labelAlign: 'right',
                        labelWidth: 80
                    },
                    items: [{
                        fieldLabel: '学员帐号',
                        name: "searchLoginID",
                        emptyText: "请输入学员帐号",
            			columnWidth: .3,
                    }, {
                        fieldLabel: "姓名",
                        name: "searchUserName",
                        emptyText: "请输入姓名",
            			columnWidth: .3,
                    },{
                        fieldLabel: '单位',
                        name: "searchDepName",
                        emptyText: "请输入单位",
            			columnWidth: .4,
                    },/*,{
    					xtype: "combo",
    					fieldLabel: '审核状态',
    					name: "auditingState",
    					store: Ext.create("Ext.data.ArrayStore", {
    						fields: ['value', 'text'],
    						data: [[1, '审核通过'],[2,'未审核通过'],[3,'未审核']]
    					}),
    					valueField: 'value',
    					displayField: 'text',
    					editable: false,
    					emptyText: "请选择"
    				}*/],
        			onResetClick: function(button){
        				
                        var form = button.up('form');
                        var gridPanel = form.grid;
                        var newParams = {
                				searchClassID: gridPanel.up('window').classId,
                				clickSource:this.up('window').clickSource,
                				auditingState: 1
                        };
                        gridPanel.getStore().proxy.extraParams = {};
                        var params = gridPanel.getStore().proxy.extraParams;
                        Ext.apply(params, newParams);
                        form.getForm().reset();
                    },
                    grid: this
                },{
                    xtype: 'toolbar',
                    dock: 'top',
                    displayInfo: true,
                    items: [{
                        text: '导出',
                        iconCls: 'deriveIco',
                        itemId: this.oldId + "Export",
                        disabled: false,
                        scope: this,
                        handler: this.onExportClick
                    }/*, "-", {
                        xtype: 'label',
                        itemId: 'signupQuotaOfPeople',
                        html: ''
                    }*/]
                }]);
    		}
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    		var params = this.store.proxy.extraParams;
    		
    		var newParams = {
    				searchClassID: this.up('window').classId,
    				clickSource:this.up('window').clickSource,
    				auditingState: 1
    		};
    		Ext.apply(params, newParams);
    		this.store.isLoad = true;
    		this.store.load();
    		//this.quotaOfPeople();//单位授人数统计
    	}
    }
});
